<?php
/**
 * Created by PhpStorm.
 * User: baike
 * Date: 2017/12/6
 * Time: 下午3:25
 */
/**
 * Created by PhpStorm.
 * User: baike
 * Date: 2017/11/30
 * Time: 下午3:59
 */

include "../mysql_connect.php";
include "../common.php";


isset($_REQUEST['server_id'])? $server_id=$_REQUEST['server_id']:$server_id="";
isset($_REQUEST['tm'])? $tm=$_REQUEST['tm']:$tm="";
isset($_REQUEST['sign'])? $sign=$_REQUEST['sign']:$sign="";
if($server_id=="" || $tm=="" || $sign=="")
{
    die("need serverid tm sign");
}

$arrparam=array();
$arrparam['server_id']=$server_id;
$arrparam['tm']=$tm;
if(!signcheck($arrparam,$sign))
{
    die(makeresultjson(-1,"checksum fail"));
}

if(!signcheck_indb($sign))
{
    die(makeresultjson(-2,"checksum fail 2"));
}


$arrhlname=array();
$sql="select * from ht_location;";
$rs=mysqli_query($_SESSION['mysqli_link'],$sql);
while($arrrs=mysqli_fetch_assoc($rs))
{
    $arrhlname[$arrrs['id'] ]=$arrrs['name'];
}
//print_r($arrhlname);

$sql="select uuid,name,area,merchant_type,ht_location_info, address from  merchant where server_id='".$server_id."';";
$rs=mysqli_query($_SESSION['mysqli_link'],$sql);
$arr_res=array();
$arr_res['return_code']=0;
$arr_res['data']=array();
while($arrrs=mysqli_fetch_assoc($rs))
{
    //extract($arrrs);

    //location_info deal;
    $trans_location_info="";
    $arr_li=explode(",",$arrrs['ht_location_info']);
    foreach ($arr_li as $i) {
        if($i!="")
        {
            $trans_location_info.=",".$arrhlname[$i];
        }
    }
    if(count($arr_li)!=1)
    {
        $trans_location_info.=",";
    }
    $arrrs['ht_location_info_trans']= $trans_location_info;
    array_push( $arr_res['data'],$arrrs);
}
echo json_encode($arr_res,JSON_UNESCAPED_UNICODE);